home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / libx11 / include / x11 / phigs / attr.h next >
C/C++ Source or Header  |  1999-01-01  |  12KB  |  329 lines

  1. /* $XConsortium: attr.h,v 5.5 91/07/18 12:57:51 hersh Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Sun Microsystems,
  13. the X Consortium, and MIT not be used in advertising or publicity 
  14. pertaining to distribution of the software without specific, written 
  15. prior permission.  
  16.  
  17. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  19. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  20. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24. ******************************************************************/
  25.  
  26. #ifndef PHG_ATTR_H_INCLUDED
  27. #define    PHG_ATTR_H_INCLUDED
  28.  
  29. typedef caddr_t *    Phg_attr_avlist;
  30. typedef unsigned    Phg_attr_attribute;        /* 32 bit quantity */
  31. /* Phg_attr_avlist is not an array of Phg_attr_attributes, because it is an array
  32.  * of intermixed attributes and values.
  33.  */
  34.  
  35. /* This macro is machine dependent in that it assumes
  36.  * the cardinality will be in the lower 5 bits of the type-cardinality
  37.  * pair.
  38.  */
  39. #define    PHG_ATTR_TYPE(base_type, cardinality) \
  40.     (((((unsigned)(base_type)) & 0x07f) << 5) |    \
  41.      (((unsigned)(cardinality)) & 0x0f))
  42.  
  43. /* Base types in the range PHG_ATTR_BASE_UNUSED_FIRST
  44.  * to PHG_ATTR_BASE_UNUSED_LAST are available for
  45.  * client use.
  46.  */
  47. #define    PHG_ATTR_BASE_UNUSED_FIRST        0
  48. #define    PHG_ATTR_BASE_UNUSED_LAST        31
  49. /* Base types 32 through 63 are
  50.  * reserved for future use.
  51.  */
  52. #define    PHG_ATTR_BASE_FIRST            64
  53.  
  54. typedef enum {
  55.     PHG_ATTR_BASE_INT        = PHG_ATTR_BASE_FIRST,
  56.     PHG_ATTR_BASE_INT_PAIR    = PHG_ATTR_BASE_FIRST + 1,
  57.     PHG_ATTR_BASE_X        = PHG_ATTR_BASE_FIRST + 2,
  58.     PHG_ATTR_BASE_INDEX_X    = PHG_ATTR_BASE_FIRST + 3,
  59.     PHG_ATTR_BASE_Y        = PHG_ATTR_BASE_FIRST + 4,
  60.     PHG_ATTR_BASE_INDEX_Y    = PHG_ATTR_BASE_FIRST + 5,
  61.     PHG_ATTR_BASE_XY        = PHG_ATTR_BASE_FIRST + 6,
  62.     PHG_ATTR_BASE_INDEX_XY    = PHG_ATTR_BASE_FIRST + 7,
  63.     PHG_ATTR_BASE_BOOLEAN    = PHG_ATTR_BASE_FIRST + 8,
  64.     PHG_ATTR_BASE_ENUM        = PHG_ATTR_BASE_FIRST + 9,
  65.     PHG_ATTR_BASE_CHAR        = PHG_ATTR_BASE_FIRST + 10,
  66.     PHG_ATTR_BASE_STRING    = PHG_ATTR_BASE_FIRST + 11,
  67.     PHG_ATTR_BASE_RECT_PTR    = PHG_ATTR_BASE_FIRST + 15,
  68.     PHG_ATTR_BASE_OPAQUE    = PHG_ATTR_BASE_FIRST + 16,
  69.     PHG_ATTR_BASE_NO_VALUE    = PHG_ATTR_BASE_FIRST + 17,
  70.     PHG_ATTR_BASE_AV        = PHG_ATTR_BASE_FIRST + 18,
  71.     PHG_ATTR_BASE_FUNCTION_PTR    = PHG_ATTR_BASE_FIRST + 19,
  72.     PHG_ATTR_BASE_ICON_PTR    = PHG_ATTR_BASE_FIRST + 20,
  73.     PHG_ATTR_BASE_INT_TRIPLE    = PHG_ATTR_BASE_FIRST + 23,
  74.     PHG_ATTR_BASE_LONG        = PHG_ATTR_BASE_FIRST + 24,
  75.     PHG_ATTR_BASE_SHORT        = PHG_ATTR_BASE_FIRST + 25
  76. } Phg_attr_base_type;
  77.  
  78. /* Clients of the attribute value package should use
  79.  * Phg_attr_base_cardinality elements to define the base type
  80.  * and cardinality of their attributes.
  81.  */  
  82. typedef enum {
  83.     PHG_ATTR_INT        = PHG_ATTR_TYPE(PHG_ATTR_BASE_INT, 1),
  84.     PHG_ATTR_INT_PAIR        = PHG_ATTR_TYPE(PHG_ATTR_BASE_INT_PAIR, 2),
  85.     PHG_ATTR_INT_TRIPLE        = PHG_ATTR_TYPE(PHG_ATTR_BASE_INT_TRIPLE, 3),
  86.     PHG_ATTR_X            = PHG_ATTR_TYPE(PHG_ATTR_BASE_X, 1),
  87.     PHG_ATTR_INDEX_X        = PHG_ATTR_TYPE(PHG_ATTR_BASE_INDEX_X, 2),
  88.     PHG_ATTR_Y            = PHG_ATTR_TYPE(PHG_ATTR_BASE_Y, 1),
  89.     PHG_ATTR_INDEX_Y        = PHG_ATTR_TYPE(PHG_ATTR_BASE_INDEX_Y, 2),
  90.     PHG_ATTR_XY            = PHG_ATTR_TYPE(PHG_ATTR_BASE_XY, 2),
  91.     PHG_ATTR_INDEX_XY        = PHG_ATTR_TYPE(PHG_ATTR_BASE_INDEX_XY, 3),
  92.     PHG_ATTR_BOOLEAN        = PHG_ATTR_TYPE(PHG_ATTR_BASE_BOOLEAN, 1),
  93.     PHG_ATTR_ENUM        = PHG_ATTR_TYPE(PHG_ATTR_BASE_ENUM, 1),
  94.     PHG_ATTR_CHAR        = PHG_ATTR_TYPE(PHG_ATTR_BASE_CHAR, 1),
  95.     PHG_ATTR_STRING        = PHG_ATTR_TYPE(PHG_ATTR_BASE_STRING, 1),
  96.     PHG_ATTR_RECT_PTR        = PHG_ATTR_TYPE(PHG_ATTR_BASE_RECT_PTR, 1),
  97.     PHG_ATTR_OPAQUE        = PHG_ATTR_TYPE(PHG_ATTR_BASE_OPAQUE, 1),
  98.     PHG_ATTR_NO_VALUE        = PHG_ATTR_TYPE(PHG_ATTR_BASE_NO_VALUE, 0),
  99.     PHG_ATTR_AV            = PHG_ATTR_TYPE(PHG_ATTR_BASE_AV, 1),
  100.     PHG_ATTR_FUNCTION_PTR    = PHG_ATTR_TYPE(PHG_ATTR_BASE_FUNCTION_PTR, 1),
  101.     PHG_ATTR_ICON_PTR        = PHG_ATTR_TYPE(PHG_ATTR_BASE_ICON_PTR, 1),
  102.     PHG_ATTR_LONG        = PHG_ATTR_TYPE(PHG_ATTR_BASE_LONG, 1),
  103.     PHG_ATTR_SHORT        = PHG_ATTR_TYPE(PHG_ATTR_BASE_SHORT, 1)
  104. } Phg_attr_base_cardinality;
  105.  
  106. /* Note that this macro is machine dependent in that it assumes the
  107.  * base_type-cardinality pair will be in the lower 13 bits of the 
  108.  * list_type-base_cardinality pair.
  109.  */
  110. #define    PHG_ATTR_LIST_OF(list_type, list_ptr_type, base_cardinality) \
  111.     (((((unsigned)(list_type)) & 0x3) << 14) | \
  112.      (((unsigned)(list_ptr_type) & 0x1) << 13) | \
  113.      (((unsigned)(base_cardinality)) & 0x3fff))
  114.  
  115. typedef enum {
  116.     PHG_ATTR_LIST_IS_INLINE    = 0,
  117.     PHG_ATTR_LIST_IS_PTR    = 1
  118. } Phg_attr_list_ptr_type;
  119.  
  120. #define    PHG_ATTR_LIST_INLINE(list_type, base_cardinality)    \
  121.     PHG_ATTR_LIST_OF(list_type, PHG_ATTR_LIST_IS_INLINE, base_cardinality)
  122.     
  123. #define    PHG_ATTR_LIST_PTR(list_type, base_cardinality)    \
  124.     PHG_ATTR_LIST_OF(list_type, PHG_ATTR_LIST_IS_PTR, base_cardinality)
  125.     
  126. typedef enum {
  127.     /* Note that PHG_ATTR_NONE must have a value of zero,
  128.      * since a no-list type is assumed for each of the
  129.      * types in Phg_attr_base_cardinality.
  130.      */
  131.     PHG_ATTR_NONE    = 0,
  132.     PHG_ATTR_RECURSIVE    = 1,
  133.     PHG_ATTR_NULL    = 2,
  134.     PHG_ATTR_COUNTED    = 3
  135. } Phg_attr_list_type;
  136.  
  137. /*
  138.  * Note that 0 is NEVER a valid package id.
  139.  *
  140.  * The range from PHG_ATTR_PKG_UNUSED_FIRST to
  141.  * PHG_ATTR_PKG_UNUSED_LAST is reserved for non-Sun packages.
  142.  */
  143. #define    PHG_ATTR_PKG_UNUSED_FIRST    1
  144. #define PHG_ATTR_PKG_UNUSED_LAST    31
  145. /* 32 through 63 are reserved for 
  146.  * future use.
  147.  */
  148. #define    PHG_ATTR_PKG_FIRST        64
  149. /* #define    PHG_ATTR_PKG_LAST        127 */
  150. /* 128 through 255 are spare */
  151.     
  152. typedef enum {
  153.     PHG_ATTR_PKG_ZERO    = 0,
  154.     PHG_ATTR_PKG_GENERIC    = PHG_ATTR_PKG_FIRST,
  155.     PHG_ATTR_PKG_LAST    = PHG_ATTR_PKG_FIRST + 18
  156. } Phg_attr_pkg;
  157.     /* Change PHG_ATTR_PKG_LAST to be EQUAL to the last legal pkg id. */
  158.     /* The procedure counter(), called by phg_attr_make, aborts if */
  159.     /* PKG_ID > PHG_ATTR_PKG_LAST */
  160.     /* PKG name should also be added to phg_attr_names[] in phg_attr.c */
  161.  
  162. /* An attribute is composed of 
  163.  * pkg     ( 8 bits): id of package that uses the attribute
  164.  * ordinal ( 8 bits): ordinal number of the attribute
  165.  * type    (16 bits): list type, list pointer type, base type, and cardinality
  166.  */
  167. #define    PHG_ATTR(pkg, type, ordinal)    \
  168.     ( ((((unsigned)(pkg))    & 0x7f) << 24) | \
  169.       ((((unsigned)(ordinal))    & 0xff) << 16) | \
  170.        (((unsigned)(type))    & 0xefef)    )
  171.  
  172. typedef union {
  173.     struct {
  174.     unsigned        pkg        : 8;
  175.     unsigned        ordinal        : 8;
  176.     unsigned        list_type    : 2;
  177.     unsigned        list_ptr_type    : 1;
  178.     unsigned        spare1        : 1;    /* unused */
  179.     unsigned        base_type    : 7;
  180.     unsigned        spare2        : 1;    /* unused */
  181.     unsigned        cardinality    : 4;
  182.     }             info;
  183.     Phg_attr_attribute    code;
  184. } Phg_attr_union;
  185.  
  186. /* Generic attributes
  187.  */
  188. typedef enum {
  189.     PHG_ATTR_LIST = PHG_ATTR(PHG_ATTR_PKG_GENERIC, PHG_ATTR_LIST_PTR(PHG_ATTR_RECURSIVE, PHG_ATTR_NO_VALUE), 0)
  190. } Phg_attr_generic;
  191.  
  192. /* PHG_ATTR_STANDARD_SIZE is large enough to allow for 
  193.  * most attribute-value lists.
  194.  */
  195. #define    PHG_ATTR_STANDARD_SIZE    250
  196.  
  197. #ifdef notdef
  198. /* Note that in these macros, attr must not be 
  199.  * in a register or be a constant.
  200.  * Since this is deemed too restrictive, we use
  201.  * shifting & masking instead.  
  202.  */
  203. #define PHG_ATTR_UNION(attr)    ((Phg_attr_union *) &((Phg_attr_attribute) (attr)))
  204. #define    PHG_ATTR_INFO(attr)        (PHG_ATTR_UNION(attr)->info)
  205. #define    PHG_ATTR_CODE(attr)        (PHG_ATTR_UNION(attr)->code)
  206. #define    PHG_ATTR_LIST_TYPE(attr)    (PHG_ATTR_INFO(attr).list_type)
  207. #define    PHG_ATTR_LIST_PTR_TYPE(attr)    (PHG_ATTR_INFO(attr).list_ptr_type)
  208. #define    PHG_ATTR_BASE_TYPE(attr)    (PHG_ATTR_INFO(attr).base_type)
  209. #define    PHG_ATTR_CARDINALITY(attr)    (PHG_ATTR_INFO(attr).cardinality)
  210. #define    PHG_ATTR_PKG(attr)        (PHG_ATTR_INFO(attr).pkg)
  211. #define    PHG_ATTR_ORDINAL(attr)    (PHG_ATTR_INFO(attr).ordinal)
  212. #endif /* notdef */
  213.  
  214. #define    PHG_ATTR_CODE(attr)        ((unsigned)(attr))
  215.  
  216. #define    PHG_ATTR_PKG(attr)    \
  217.     ((Phg_attr_pkg) ((PHG_ATTR_CODE(attr) >> 24) & 0xFF))
  218.  
  219. #define PHG_ATTR_VALID_PKG_ID(attr)        \
  220.     (((int)PHG_ATTR_PKG(attr)) > ((int) PHG_ATTR_PKG_ZERO) && \
  221.      ((int)PHG_ATTR_PKG(attr)) <= ((int)PHG_ATTR_PKG_LAST))
  222.  
  223. #define    PHG_ATTR_ORDINAL(attr)    \
  224.     ((unsigned) ((PHG_ATTR_CODE(attr) >> 16) & 0xFF))
  225.  
  226. #define    PHG_ATTR_LIST_TYPE(attr)    \
  227.     ((Phg_attr_list_type) ((PHG_ATTR_CODE(attr) >> 14) & 0x3))
  228.  
  229. #define    PHG_ATTR_LIST_PTR_TYPE(attr)    \
  230.     ((Phg_attr_list_ptr_type) ((PHG_ATTR_CODE(attr) >> 13) & 0x1))
  231.  
  232. #define    PHG_ATTR_BASE_TYPE(attr)    \
  233.     ((Phg_attr_base_type) ((PHG_ATTR_CODE(attr) >> 5) & 0x7F))
  234.  
  235. #define    PHG_ATTR_CARDINALITY(attr)    \
  236.     ((unsigned) (PHG_ATTR_CODE(attr) & 0xF))
  237.  
  238.  
  239. /* Character unit support */
  240.  
  241. #ifdef    lint
  242. /* The following #ifndef fixes kernel lint warnings, but is pretty strange */
  243. #ifndef lint
  244. extern    void    phg_attr_replace_cu();
  245. extern    int    phg_attr_cu_to_x();
  246. extern    int    phg_attr_cu_to_y();
  247. #endif
  248. #else    /* lint */
  249. #define phg_attr_replace_cu(avlist, font, lmargin, tmargin, rgap) \
  250.     phg_attr_rc_units_to_pixels(avlist, font->pf_defaultsize.x, \
  251.     font->pf_defaultsize.y, lmargin, tmargin, 0, rgap)
  252.     
  253. #define phg_attr_cu_to_x(encoded_value, font, left_margin) \
  254.     phg_attr_rc_unit_to_x(encoded_value, font->pf_defaultsize.x, left_margin, 0)
  255.  
  256. #define phg_attr_cu_to_y(encoded_value, font, top_margin, row_gap) \
  257.     phg_attr_rc_unit_to_y(encoded_value, font->pf_defaultsize.y, top_margin, row_gap)
  258. #endif    /* lint */
  259.  
  260. typedef enum {
  261.     PHG_ATTR_CU_POSITION    = 0x0,        /* bit 29 is off */
  262.     PHG_ATTR_CU_LENGTH    = 0x20000000    /* bit 29 is on */
  263.  
  264. } Phg_attr_cu_type;
  265.  
  266. #define    PHG_ATTR_CU_TAG        0x80000000
  267. #define PHG_ATTR_PIXEL_OFFSET    0x00008000
  268.  
  269. #define    PHG_ATTR_CU(unit, n)    \
  270.    (((unsigned)(unit)) | (((unsigned)(n) & 0x1FFF) << 16) |    \
  271.     PHG_ATTR_CU_TAG | PHG_ATTR_PIXEL_OFFSET)
  272.     
  273. #define    PHG_ATTR_CU_MASK        0xC0000000
  274. #define    PHG_ATTR_CU_TYPE(n)        \
  275.     ((Phg_attr_cu_type) ((n) & (unsigned) (PHG_ATTR_CU_LENGTH)))
  276.  
  277. /* phg_attr_is_cu(n) returns non-zero if n has 
  278.  * been encoded using PHG_ATTR_CU()
  279.  */
  280. #define    phg_attr_is_cu(n)        (((n) & PHG_ATTR_CU_MASK) == PHG_ATTR_CU_TAG)
  281.  
  282. /* Macros for position including
  283.  * margins.
  284.  */
  285. #define    PHG_ATTR_COL(n)        PHG_ATTR_CU(PHG_ATTR_CU_POSITION, n)
  286. #define    PHG_ATTR_ROW(n)        PHG_ATTR_CU(PHG_ATTR_CU_POSITION, n)
  287.  
  288. /* Macros for length excluding
  289.  * margins.
  290.  */
  291. #define    PHG_ATTR_COLS(n)    PHG_ATTR_CU(PHG_ATTR_CU_LENGTH, n)
  292. #define    PHG_ATTR_ROWS(n)    PHG_ATTR_CU(PHG_ATTR_CU_LENGTH, n)
  293. #define    PHG_ATTR_CHARS(n)    PHG_ATTR_CU(PHG_ATTR_CU_LENGTH, n)
  294. #define    PHG_ATTR_LINES(n)    PHG_ATTR_CU(PHG_ATTR_CU_LENGTH, n)
  295.    
  296.  
  297. /* phg_attr_make() is not interested in the
  298.  * count from phg_attr_make_count().
  299.  */
  300. #define    phg_attr_make(array, max_size, argv)    \
  301.     phg_attr_make_count(array, max_size, argv, (int *)0)
  302.  
  303. /* Following are useful for multi-pass avlist processing. */
  304. #define    PHG_ATTR_NOP(attr)                    \
  305.      ( (((unsigned)PHG_ATTR_PKG_NOP) << 24) | (PHG_ATTR_CODE(attr) & 0xffffff) )
  306. #define    PHG_ATTR_CONSUME(attr)    (attr) = ((caddr_t)PHG_ATTR_NOP(attr))
  307.  
  308. #define    phg_attr_skip(attr, argv)    \
  309.     ((PHG_ATTR_LIST_TYPE((attr)) == PHG_ATTR_NONE) \
  310.     ? (argv) + PHG_ATTR_CARDINALITY((attr)) \
  311.     : ((Phg_attr_avlist)phg_attr_skip_value((Phg_attr_attribute)(attr), (argv))))
  312.  
  313. #define    phg_attr_next(attrs)    phg_attr_skip((*(attrs)), ((attrs)+1))
  314.  
  315. #ifndef lint
  316. /* Available functions
  317.  */
  318. extern Phg_attr_avlist    phg_attr_create_list();
  319. extern Phg_attr_avlist    phg_attr_create();
  320. extern Phg_attr_avlist    phg_attr_make_count();
  321. extern int        phg_attr_copy();
  322. extern int        phg_attr_count();
  323. extern char            *phg_attr_sprint();
  324. extern void        phg_attr_free();
  325. extern Phg_attr_avlist    phg_attr_skip_value();
  326. #endif /* lint */
  327. #endif
  328.  
  329.